<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/11/10
  Time: 16:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<head>
    <title>Title</title>
</head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css">
<link rel="stylesheet"
      href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/static/bootstrap-treeview/js/bootstrap-treeview.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#usertb").bootstrapTable({
            url: "${pageContext.request.contextPath}/byname",
            pagination: true,
            height: 500,
            pageList: [5, 10, 100],
            pageSize: 5,
            sidePagination: "server",
            striped: true,
            /*后台传值*/
            queryParamsType: '',
            queryParams: query,
            columns: [
                {field: "id", title: "编号"},
                {field: "userName", title: "姓名"},
                {field: "address", title: "地址"},
                {field: "phone", title: "手机号码"},
                {field: "birthday", title: "出生日期"},
                {field: "gender", title: "性别",
                    formatter: function (value, row, index) {
                        if (row.gender == 1) {
                            return "男"
                        } else {
                            return "女"
                        }
                    },
                }, {
                    title: "操作",
                    formatter: function (value, row, index) {
                        return "<button class='btn btn-default' onclick='update(" + row.id + ")'>修改</button>"
                    }
                }
            ]
        })
    })

    /*传值*/
    function query(params) {
        var temp = {
            'userName': $('#name').val(),
            'offset': params.pageNumber,
            'limit': params.pageSize
        }
        return temp;
    }

    //   条件查询
    function search() {
        var username = $('#name').val();
        $.ajax({
            url: "${pageContext.request.contextPath}/byname",
            data: {
                'userName': username,
                'offset': 1,
                'limit': 5
            },
            success: function (date) {
                $('#usertb').bootstrapTable('load', date)
            }
        })
    }
    function update(id) {
        alert(id)
        $("#modal-id").modal("show");
    }
</script>
<body>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">用户列表</h3></div>
</div>
<div class="panel-body">
    <form class="form-inline" style="float: right">
        <div class="form-group">
            <input type="text" id="name" class="form-control" placeholder="请输入关键词"/>
        </div>
        <button type="button" onclick="search()" class="btn btn-primary">查询</button>
    </form>
</div>
<table id="usertb"></table>
<div class="modal fade" id="modal-id">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class=="modal-title">提示信息</h4>
            </div>
            <div class="modal-body">
                <div id="searchTree"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary">修改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script>
    //    树形菜单id
    var treeDate = [
        {
            text: "Parent 1",
            id: 1,
            nodes: [{
                text: "Child 1",
                id: 2,
                nodes: [{
                    text: "Grandchild 1",
                    id: 3,
                }, {
                    text: "Grandchild 2",
                    id: 4
                }]
            }, {
                text: "Child 2",
                id: 5,
                nodes: [{
                    text: "Grandchild 1",
                }]
            }
            ]
        },
        {
            text: "Parent 2",
            id: 6,
            nodes: [{
                text: "child3",
                nodes: [{
                    text: "Grand Child4"
                }]
            }, {
                text: "child 4",
                nodes: [{
                    text: "Grand Child 5"
                }]
            }]
        },
        {
            text: "Parent 3",
            id: 7
        },
        {
            text: "Parent 4",
            id: 8
        },
        {
            text: "Parent 5",
            id: 9
        }
    ];

    $('#searchTree').treeview({
        //显示复选框
        data: treeDate,
        //显示复选框
        showCheckbox: true,

    });


</script>
</html>
